from app import db

class Company(db.Model):
    __tablename__ = 'companies'
    
    id = db.Column(db.Integer, primary_key=True)
    cid = db.Column(db.String(20), nullable=False)
    cname = db.Column(db.String(20), nullable=False)
    pid = db.Column(db.String(20), nullable=False)
    created_at = db.Column(db.DateTime, default=db.func.current_timestamp())  

    def to_dict(self):
        """转换为字典，方便接口返回"""
        return {
            'id': self.id,
            'cid': self.cid,
            'cname': self.cname,
            'pid': self.pid,
            'created_at': self.created_at.isoformat()
        }
